package com.eternal.base.data.ble;

import com.eternal.base.database.entity.Log;
import com.eternal.base.protocol.ProtocolResolution;
import com.eternal.base.protocol.ProtocolTransformer;

public class LogParse extends BaseParse<Log> {
    private long time;
    private byte logType;

    public LogParse(long time) {
        this.time = time;
    }

    @Override
    boolean checkLength() {
        if(logType==0){
            return i+28<now.length;
        }else{
            return i+19<now.length;
        }
    }

    @Override
    Log parse() {
        Log log;
        if(logType==0){
            log=ProtocolResolution.parseLog(now, i, time);
            i+=28;
        }else{
            log= ProtocolResolution.parseCLog(now, i, time);
            i+=19;
        }
        --total;
        return log;
    }

    @Override
    void init() {
        i=20;
        total=now[18];
        logType=now[19];
        if(now[9]!=0x12){
            total=0;
            i=now.length;
        }
    }
}
